package com.nchu.controller;

import com.nchu.mappers.OrdertransationMapper;
import com.nchu.mappers.UserMapper;
import com.nchu.pojo.OrderTransation;
import com.nchu.pojo.User;
import com.nchu.service.EvaluationService;
import com.nchu.service.OrderTransationService;
import com.nchu.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpSession;
import java.util.List;

@Controller
@RequestMapping("/transation")
public class TransationController {
    @Autowired
    private OrdertransationMapper service ;

    @Autowired
    private UserService userService;


    @RequestMapping("/findall")
    public String findall(Model model)
    {
        List<OrderTransation> listall;
        listall=service.findall();
        model.addAttribute("transationlistall",listall);
        listall.stream().forEach(System.out::println);
        return "all";
    }
    @RequestMapping("/findone")
    public String findone(Model model)
    {
        OrderTransation listone;
        listone=service.findone(1001);
        model.addAttribute("transationlistone",listone);
        System.out.println(listone);
        return "all";
    }
    @RequestMapping("/delectone")
    public String delectone(Model model)
    {
        OrderTransation listone;
        listone=service.findone(1001);
        if(listone!=null){
            System.out.println(service.delectone(1001));
            return "all";
        }
        else {
            model.addAttribute("msg","不纯在这个用户");
        }
        return "all";
    }
    @RequestMapping("mybill")
    public String mybill(Model model, HttpSession session){
        User user = (User) session.getAttribute("user");
        Integer userid=user.getUserId();
        User user1 = userService.userisexist(userid);
        List<OrderTransation> mybill = service.mybill(userid);
        model.addAttribute("mybill",mybill);
        model.addAttribute("user",user1);
        session.setAttribute("user",user1);
        mybill.stream().forEach(System.out::println);
        return "money";
    }
}
